package cn.meizhu.user.service.impl;

import cn.meizhu.base.exception.Exceptions;
import cn.meizhu.base.service.impl.BaseServiceImpl;
import cn.meizhu.user.domain.LoginInfo;
import cn.meizhu.user.domain.tro.UserDto;
import cn.meizhu.user.mapper.LoginInfoMapper;
import cn.meizhu.user.service.ILoginInfoService;
import cn.meizhu.util.MD5Utils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;



@Service
public class LoginInfoServiceImpl extends BaseServiceImpl<LoginInfo> implements ILoginInfoService {

    @Autowired
    private LoginInfoMapper loginInfoMapper;



    @Override
    public LoginInfo login(UserDto userDto) throws Exceptions {
        LoginInfo loginInfo = loginInfoMapper.findByAccount(userDto.getPhone());
        if (loginInfo == null){
            throw new Exceptions("用户名或密码错误");
        }
        String byMd5 = MD5Utils.encrypByMd5(userDto.getPassword() + loginInfo.getSalt());
        if (!byMd5.equals(loginInfo.getPassword())){
            throw new Exceptions("用户名或密码错误");
        }
        return loginInfo;
    }

}
